package com.meitianhui.convenitenbuy.module.home.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.main.http.MainApiDataSource;
import com.meitianhui.convenitenbuy.module.home.contract.BrandWebViewContract;
import com.meitianhui.convenitenbuy.module.home.model.bean.OneOrder;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.BrandWebViewActivity;
import com.meitianhui.convenitenbuy.module.mine.model.UserAsset;

import java.util.HashMap;
import java.util.Map;

public class BrandWebViewPresenter implements BrandWebViewContract.Presenter {

    private BrandWebViewActivity context;
    private BrandWebViewContract.View view;

    public BrandWebViewPresenter(BrandWebViewContract.View view, BrandWebViewActivity context) {
        this.view = view;
        this.context = context;
    }

    @Override
    public void getUserAsset(OneOrder oneOrder) {
        Map<String, String> map = new HashMap<>();
        map.put("member_id", InfoProvider.getUserToken(context).getMember_id());
        String json = new Gson().toJson(map);

        MainApiDataSource.getInstance()
                .getUserAsset(InfoProvider.getUserToken(context).getUser_token(),
                        "finance.memberAssetFind", json)
                .subscribe(new ResponseObserver<BaseResponse<UserAsset>>(context) {
            @Override
            public void onSuccess(BaseResponse<UserAsset> response) {
                view.getUserAssetSuccess(response.data, oneOrder);
            }

            @Override
            public void onFail(int code, String msg) {
                super.onFail(code, msg);
            }
        });
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

}
